﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Ccit.OA.Utils;

namespace Ccit.Mgoa.Collaboration
{
    public partial class collaboration_type_index : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindGrid();
        }

        private void BindGrid()
        {
            CollaborateBLL oCollaborate = new CollaborateBLL();
            MsQuery msQuery = new MsQuery();
            List<MsCollaborativeType> lstCollaborativeType = oCollaborate.GetCollaborativeType(msQuery);
            gvCollaborationTypeList.DataSource = lstCollaborativeType;
            gvCollaborationTypeList.DataBind();
        }

        protected void gvCollaborationTypeList_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;

            string sTypeId = e.KeyValue.ToString();
            string sCreatorId = gvCollaborationTypeList.GetRowValues(e.VisibleIndex, "Creator").ToString();
            e.Row.Cells[3].Text = SysInterface.GetNameStrByIdStr(sCreatorId, NameType.USER, ",");

            HtmlAnchor haEdit = (HtmlAnchor)gvCollaborationTypeList.FindRowCellTemplateControl(e.VisibleIndex, null, "haEdit");
            HtmlAnchor haDelete = (HtmlAnchor)gvCollaborationTypeList.FindRowCellTemplateControl(e.VisibleIndex, null, "haDelete");

            haEdit.Attributes["href"] = "javascript:doEdit(" + sTypeId + ")";
            haDelete.Attributes["href"] = "javascript:doDelete(" + sTypeId + ")";
        }

        protected void lnkRefresh_Click(object sender, EventArgs e)
        {
            BindGrid();
        }

        /// <summary>
        /// 删除协作类型
        /// </summary>
        /// <param name="sTypeIds"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static bool DeleteCollaborativeType(string sTypeIds)
        {
            bool bFlag = false;
            CollaborateBLL oCollaborate = new CollaborateBLL();
            bFlag = oCollaborate.DeleteCollaborativeType(sTypeIds);
            oCollaborate = null;
            return bFlag;
        }
    }
}
